//
//  FirstTableViewCell.m
//  味·道
//
//  Created by 刘孝纯 on 15/6/30.
//  Copyright (c) 2015年 WMR. All rights reserved.
//

#import "FirstTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "MaocHeader.h"
@implementation FirstTableViewCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _imageview = [[UIImageView alloc] initWithFrame:CGRectMake(10, 15, SCREEN_WIDTH - 20, 200)];
        self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 200, SCREEN_WIDTH-20, 15)];
        self.titleLable.font = [UIFont systemFontOfSize:10];
        [self.titleLable setTextColor:[UIColor whiteColor]];
        self.titleLable.textAlignment = NSTextAlignmentCenter;
        _tagLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 230, SCREEN_WIDTH-20, 12)];
        _tagLable.font = [UIFont systemFontOfSize:12];
        self.jianjie = [[UILabel alloc] initWithFrame:CGRectMake(10, 245, SCREEN_WIDTH-20, 100)];
        self.jianjie.font = [UIFont systemFontOfSize:10];
        self.jianjie.numberOfLines = 0;
        
        
        [self.contentView addSubview:_imageview];
        [self.contentView addSubview:_tagLable];
        [self.contentView addSubview:_jianjie];
        [self.contentView addSubview:_titleLable];
        
        [_imageview release];
        [_tagLable release];
        [_jianjie release];
        [_titleLable release];
    }
    return self;
}
-(void)setModel:(RecommendModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:model.thumb] placeholderImage:[UIImage imageNamed:@"placeholder"]];
    _titleLable.text = model.title;
    
    _tagLable.text =model.tags;
    _jianjie.frame = CGRectMake(10, 245, SCREEN_WIDTH-20, [FirstTableViewCell heightForjianjie:model.jianjie]);
    _jianjie.text = model.jianjie;
    
}
+(CGFloat)heightForjianjie:(NSString *)str
{
    NSDictionary *dict = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:10] forKey:NSFontAttributeName];
    CGRect bounds = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH-20, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dict context:nil];
    return bounds.size.height;
}
+(CGFloat)heightForCell:(RecommendModel *)model
{
    CGFloat jianjieHeight = [FirstTableViewCell heightForjianjie:model.jianjie];
    return 245+jianjieHeight+20;
  
}
@end
